#include "StdAfx.h"
#include "Drag.h"

CDrag::CDrag(void)
{
	m_pdragobj = 0;
}

CDrag::~CDrag(void)
{
	SAFE_DELETE(m_pdragobj);
}

void	CDrag::SetDragObject( CDragObject* pdragobj )
{
	if(m_pdragobj)
		m_pdragobj->Clear();
	SAFE_DELETE(m_pdragobj);
	m_pdragobj = pdragobj;
}

UINT	CDrag::MsgProc(UINT message, WPARAM wParam, LPARAM lParam )
{
	if(!m_pdragobj)
		return 0;

	switch(message)
	{
	case WM_MOUSEMOVE:
		if(m_pdragobj)
			m_pdragobj->SetPos(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
		break;
	case WM_LBUTTONUP:
	case WM_LBUTTONDOWN:
		INSTANCE_APP->SendMessage(CMS_DRAG,wParam,lParam);
		SetDragObject(0);
		return TRUE;
	case WM_KEYDOWN:
		if(wParam == VK_ESCAPE)
		{
			SetDragObject(0);
			return TRUE;
		}
		break;		
	case WM_RBUTTONDOWN:
		SetDragObject(0);
		break;
	default:
		if(message>=WM_MOUSEFIRST && message<=WM_MOUSELAST+1)
			return TRUE;
		break;
	};
	return 0;
}

void	CDrag::Render( )
{
	if(m_pdragobj)
		m_pdragobj->Render( );
}
